<template>
    <el-dialog 
    :title="dialog.title || ''"
    :destroy-on-close="true"
    :before-close="handleClose"
    :close-on-click-modal="false"
    :visible="dialog.visible">
        <component :is="dialog.component"></component>
    </el-dialog>
</template>

<script>
    export default {
        name: 'r-dialog',
        data () {
            return {
                msg: 'sdfsdf'
            }
        },
        methods: {
            handleClose () {
                if (this.dialog.onClose) {
                    if (this.dialog.onClose()) this.$store.commit('closeDialog')
                } else {
                    this.$store.commit('closeDialog')
                }
            }
        },
        computed: {
            visible () {
                return this.$store.state.dialog.visible
            },
            dialog () {
                return this.$store.state.dialog
            }
        }
    }
</script>